/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Prestahop_retrievement;

import com.insa.a1.hibernate.ps.PsOrders;
import com.insa.a1.xmladapter.DateAdapter;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 *
 * @author strokyl
 */
@Entity
public class Orders implements Serializable {

	@Id
	private int idOrder;
	private float totalPaid;

	@Temporal(TemporalType.TIMESTAMP)
	@XmlJavaTypeAdapter(DateAdapter.class)
	private Date dateUppAdd;

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "id_cart", columnDefinition = "int")
	private Cart cart;

	@ManyToOne
	@XmlInverseReference(mappedBy = "orders")
	private Customer customer;

	Orders(PsOrders ps, Customer customer) {
		this.cart = new Cart(ps.getCart(), this);
		this.totalPaid = ps.getTotalPaid().floatValue();
		this.dateUppAdd = ps.getDateUpd();
		this.idOrder = ps.getIdOrder();
		this.customer = customer;
	}

	public Orders() {
	}

	public Cart getCart() {
		return cart;
	}

	public void setCart(Cart cart) {
		this.cart = cart;
	}

	public Date getDateUppAdd() {
		return dateUppAdd;
	}

	public void setDateUppAdd(Date dateUppAdd) {
		this.dateUppAdd = dateUppAdd;
	}

	public int getIdOrder() {
		return idOrder;
	}

	public void setIdOrder(int idOrder) {
		this.idOrder = idOrder;
	}

	public float getTotalPaid() {
		return totalPaid;
	}

	public void setTotalPaid(float totalPaid) {
		this.totalPaid = totalPaid;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@Override
	public String toString() {
		return String.format("Order( %s , %s )", idOrder, totalPaid);
	}

	public Date getLastUpdateDate() {
		return dateUppAdd;
	}

}
